package com.zhang.boot.core.vo.request;

import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @Author zhangshaobin
 * @Date 2020/10/30
 * @Description 请求信息
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class RequestInfo implements Serializable {
    private String requestTime;
    private String uri;
    private String requestParam;
    private String requestHeader;
    private String response;
    private Long totalTime;

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("{");
        stringBuilder.append("\"请求时间\": \"" + requestTime + "\"");
        stringBuilder.append(",\"请求地址\": \"" + uri + "\"");
        if (StrUtil.isNotBlank(requestParam)) {
            stringBuilder.append(",\"请求参数\": " + requestParam);
        } else {
            stringBuilder.append(",\"请求参数\": \"" + requestParam + "\"");
        }
        stringBuilder.append(",\"请求头\": " + requestHeader);
        if (StrUtil.isNotBlank(response)) {
            stringBuilder.append(",\"响应\": " + response);
        }
        if (totalTime != null) {
            stringBuilder.append(",\"请求耗时\": \"" + totalTime + "ms\"");
        }
        stringBuilder.append("}");
        return stringBuilder.toString();
    }
}
